<template>
	<view class="roster-container">
		<view class="roster-top">
			<view class="roster-search-container">
				<commonIcon type="icon-a-sousuo1x" :size="24" />
				<input type="text" disabled placeholder="搜索姓名/手机号/证件号" placeholder-class="placeholder-class" class="search-ipt" @tap="toRosterSearch" />
			</view>
			<view class="org-info-container">
				<view class="org-info">
					<view class="info-item-container">
						<text class="info-item-label">总计</text>
						<text class="info-item-content">{{ countMap.total }}人</text>
					</view>
					<view class="info-item-container">
						<text class="info-item-label">管理</text>
						<text class="info-item-content">{{ countMap.managerTotal }}人</text>
					</view>
					<view class="info-item-container">
						<text class="info-item-label">劳务</text>
						<text class="info-item-content">{{ countMap.builderTotal }}人</text>
					</view>
				</view>
				<picker mode="selector" :value="selectIndex" class="state-container" :range="workingStatusList" range-key="value" @change="changeWorkStatus">
					<view class="state">
						<text>{{ workingStatusList[selectIndex].value }}</text>
						<text class="down-arrow"></text>
					</view>
				</picker>
			</view>
		</view>
		<scroll-view class="scroll-view" scroll-y scroll-with-animation refresher-enabled :refresher-triggered="isPullRefresh" @refresherrefresh="getParentOrgnation" enable-flex>
			<view class="project-list" v-if="orgnationList.length != 0">
				<view class="project-item-container" v-for="(item, index) in orgnationList" :key="index">
					<view class="projext-item" @tap="toRosterOrg" :data-item="item">
						<commonIcon type="icon-xiangmu" :size="82" v-if="item.type == 2 && item.orgType == 4" />
						<commonIcon type="icon-gongsibanzu" :size="82" v-else />
						<view class="project-item-middle">
							<view class="middle-top">
								<text class="project-type" v-if="item.type == 1">子</text>
								<text class="project-name">{{ item.name }}</text>
							</view>
							<view class="middle-bottom">
								<view class="project-tag" v-for="(tagItem, tagIndex) in item.tags" :key="tagIndex">
									<text class="tag-name">{{ tagItem.key }}</text>

									<text class="tag-num">{{ tagItem.value }}</text>
								</view>
							</view>
						</view>
						<text class="right-arrow"></text>
					</view>
				</view>
			</view>
			<view class="no-data" v-else>
				<no-data></no-data>
			</view>
		</scroll-view>
		<!-- <view class="common-btns-container" v-if="underReviewCount != 0 && hasApproval">
			<view class="common-btn-container" hover-class="common-btn" @tap="toApproval">
				<text>待审批({{ underReviewCount }})</text>
				<text class="right-arrow"></text>
			</view>
		</view> -->
	</view>
</template>

<script>
import commonIcon from '@/pagesA/components/common/icon/icon';
import noData from '@/pagesA/components/common/no-data/no-data';
import { workingStatusList } from '@/pagesA/config/enum';
import { common } from '@/pagesA/utils/common.js';
const app = getApp();
export default {
	components: {
		noData,
		commonIcon
	},
	data() {
		return {
			hasApproval: false,
			workingStatusList,
			workingStatus: 1,
			selectIndex: 1,
			underReviewCount: 0,
			countMap: {
				total: '',
				managerTotal: '',
				builderTotal: ''
			},
			orgnationList: [],
			isPullRefresh: false,
			value: '',
			tagIndex: 0,
			tagItem: {
				key: '',
				value: ''
			}
		};
	},
	onLoad(options) {
		this.workingStatusList.unshift({
			code: '',
			value: '全部'
		});
		common.init();
		// this.setData({
		// 	workingStatusList: this.workingStatusList
		// });
	},
	onShow() {
		this.getParentOrgnation();
		this.handleApprovalAuth();
	},
	methods: {
		handleApprovalAuth() {
			let cisdiOpearList = uni.getStorageSync('cisdiOpearList');
			let hasApproval = false;
			if (cisdiOpearList) {
				for (let item of cisdiOpearList) {
					if (item == '20131062') {
						hasApproval = true;
						break;
					}
				}
			}
			// this.setData({
			// 	hasApproval
			// });
			this.hasApproval = hasApproval;
		},
		getParentOrgnation() {
			let postData = {
				workingStatus: this.workingStatus,
				calculateModify: 1
			};
			if (!postData.workingStatus) {
				delete postData.workingStatus;
			}
			this.isPullRefresh = true;
			this.$nextTick(() => {
				this.isPullRefresh = false;
			});
			common.apis.roster.getParentOrgnation(postData).then(
				(res) => {
					if (!res.data) {
						return;
					}
					// this.setData({
					// 	isPullRefresh: false,
					// 	countMap: res.data.countMap,
					// 	orgnationList: res.data.orgnationList,
					// 	underReviewCount: res.data.underReviewCount
					// });
					this.isPullRefresh = false;
					this.countMap = res.data.countMap;
					this.orgnationList = res.data.orgnationList;
					this.underReviewCount = res.data.underReviewCount;
				},
				() => {
					// this.setData({
					// 	isPullRefresh: false
					// });
					this.isPullRefresh = false;
				}
			);
		},
		changeWorkStatus(e) {
			let index = e.detail.value;
			// this.setData({
			// 	selectIndex: index,
			// 	workingStatus: this.workingStatusList[index].code
			// });
			this.selectIndex = index;
			this.workingStatus = this.workingStatusList[index].code;
			this.getParentOrgnation();
		},

		toRosterOrg(e) {
			const item = e.currentTarget.dataset.item;
			if (item.type == 1) {
				uni.navigateTo({
					url: `/pagesA/pages/roster/rosterOrg/rosterOrg?projectUuid=${item.uuid}&workingStatus=${this.workingStatus}&type=${item.type}&orgName=${item.name}&workTeamUuid=`
				});
			} else {
				uni.navigateTo({
					url: `/pagesA/pages/roster/rosterOrg/rosterOrg?projectUuid=&workingStatus=${this.workingStatus}&type=${item.type}&orgName=${item.name}&workTeamUuid=${item.uuid}`
				});
			}
		},
		toRosterSearch() {
			uni.navigateTo({
				url: '/pagesA/pages/roster/rosterOrg/rosterSearch/rosterSearch'
			});
		},
		toApproval() {
			uni.navigateTo({
				url: '/pagesA/pages/roster/approval/approval'
			});
		}
	}
};
</script>
<style>
.roster-container {
	display: flex;
	flex-direction: column;
	height: 100vh;
	background-color: #f6f7fa;
}

.roster-top {
	background-color: #fff;
	padding: 0 32rpx;
}

.roster-search-container {
	height: 64rpx;
	background: #eff1f6;
	border-radius: 8rpx;
	display: flex;
	align-items: center;
	box-sizing: border-box;
	padding: 12rpx 24rpx;
}

.search-ipt {
	margin-left: 8rpx;
}

.placeholder-class {
	font-size: 26rpx;
}

.org-info-container {
	display: flex;
	align-items: center;
	justify-content: space-between;
	margin: 24rpx 0 8rpx;
	overflow: hidden;
}

.org-info {
	flex: 1;
	overflow: hidden;
	white-space: nowrap;
	display: flex;
	align-items: center;
	font-size: 28rpx;
	font-family: PingFangSC-Regular, PingFang SC;
	font-weight: 400;
	color: #949dbf;
	word-break: break-all;
}

.info-item-container {
	display: flex;
	align-items: center;
}

.info-item-container::after {
	content: '';
	display: block;
	width: 2rpx;
	height: 24rpx;
	background: #949dbf;
	margin: 0 16rpx;
}

.info-item-container .info-item-label {
	margin-right: 8rpx;
	flex-shrink: 0;
}

.info-item-container:last-child::after {
	content: '';
	width: 0;
	height: 0;
}

.info-item-container:last-child {
	overflow: hidden;
}

.info-item-container:last-child .info-item-content {
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.state-container {
	width: fit-content;
	flex-shrink: 0;
	margin-left: 12rpx;
}

.state-container .state {
	display: flex;
	align-items: center;
	font-size: 28rpx;
	font-family: PingFangSC-Regular, PingFang SC;
	font-weight: 400;
	color: #4b5680;
}

.state .down-arrow {
	width: 15rpx;
	height: 15rpx;
	border-top: 4rpx solid #949dbe;
	border-right: 4rpx solid #949dbe;
	transform: rotate(135deg);
	border-radius: 4rpx;
	margin: 0 12rpx;
	position: relative;
	top: -4rpx;
}

.scroll-view {
	height: 0;
	flex: 1;
}

.project-list {
	padding-bottom: 32rpx;
}

.project-item-container {
	padding-left: 32rpx;
	background-color: #fff;
}

.projext-item {
	display: flex;
	border-bottom: 1px solid #e1e2e7;
	padding-top: 32rpx;
	padding-right: 32rpx;
	padding-bottom: 32rpx;
}

.project-item-container:last-child .projext-item {
	border-bottom: 0;
}

.project-item-container .project-item-icon {
	width: 82rpx;
	height: 82rpx;
	border: 1rpx solid;
}

.project-item-container .project-item-middle {
	flex: 1;
	margin-left: 24rpx;
	overflow: hidden;
}

.project-item-middle .middle-top {
	display: flex;
	align-items: center;
	font-size: 34rpx;
	font-family: PingFangSC-Medium, PingFang SC;
	font-weight: 550;
	color: #1e253f;
}

.middle-top .project-type {
	width: 38rpx;
	height: 38rpx;
	background-color: #ff9542;
	border-radius: 50%;
	font-size: 26rpx;
	padding: 4rpx;
	color: #fff;
	text-align: center;
	font-weight: 400;
	margin-right: 6rpx;
	flex-shrink: 0;
}

.middle-top .project-name {
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.project-item-middle .middle-bottom {
	display: flex;
	align-items: center;
	flex-wrap: wrap;
}

.middle-bottom .project-tag {
	display: flex;
	align-items: center;
	justify-content: center;
	width: fit-content;
	height: 40rpx;
	background: #eff1f6;
	border-radius: 6rpx;
	font-size: 24rpx;
	font-family: PingFangSC-Regular, PingFang SC;
	font-weight: 400;
	color: #4b5680;
	padding: 0 20rpx 0 25rpx;
	margin-right: 16rpx;
	margin-top: 16rpx;
	flex-shrink: 0;
}

.project-tag .tag-num {
	word-break: break-all;
	margin-left: 5rpx;
}

.projext-item .right-arrow {
	flex-shrink: 0;
	align-self: center;
	width: 15rpx;
	height: 15rpx;
	border-top: 4rpx solid #949dbe;
	border-right: 4rpx solid #949dbe;
	transform: rotate(45deg);
	border-radius: 4rpx;
	margin-left: 32rpx;
}

.common-btn-container {
	display: flex;
	align-items: center;
	background-color: rgba(63, 100, 250, 0.1);
	color: #3f64fa;
}

.common-btn-container .right-arrow {
	width: 14rpx;
	height: 14rpx;
	border-top: 4rpx solid #3f64fa;
	border-right: 4rpx solid #3f64fa;
	transform: rotate(45deg);
	border-radius: 4rpx;
	margin-left: 6rpx;
}

.no-data {
	height: 100%;
}
</style>
